import mainRequest from '@/service/index'
import { IAccount, ILoginResult, IUserInfoResult } from './types'
import { IDataType } from '../types'

enum LoginApi {
  AccountLogin = '/login',
  LoginUserInfo = '/users/', // 用法: /users/id
  LoginUserMenus = '/role/' // 用法: role/id/menu
}

export function accountLoginRequest(account: IAccount) {
  return mainRequest.post<IDataType>({
    url: LoginApi.AccountLogin,
    data: account
  })
}

export function requestUserInfoById(id: number) {
  return mainRequest.get<IDataType<IUserInfoResult>>({
    url: LoginApi.LoginUserInfo + id
  })
}

export function requestUserMenusByRoleId(id: number) {
  return mainRequest.get<IDataType>({
    url: LoginApi.LoginUserMenus + id + '/menu'
  })
}
